//
//  LawListCell.m
//  cityStar
//
//  Created by joyban on 15-1-19.
//  Copyright (c) 2015年 tiny. All rights reserved.
//

#import "LawListCell.h"
#import "UIColor+FlatUI.h"

@implementation LawListCell

+(CGFloat)heightOfTableCell
{
    return 88;
}

- (void)awakeFromNib {
    // Initialization code
}

-(void)setDataLaw:(LawArrayModel *)model
{
    self.titleLabel.text = model.title;
    self.namelabel.text = model.contact;
    self.telphonelabel.text = model.phone;
    self.addresslabel.text = model.district_name;
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[[NSString stringWithFormat:@"%@",model.modify_time] intValue]];
    NSLog(@"date1:%@",confromTimesp);
    self.timelabel.text = [self dateStringFromNow:confromTimesp];
    NSInteger typestring = [[NSString stringWithFormat:@"%@",model.style] integerValue];
    switch (typestring) {
        case 0:
            self.typelabel.text = @"咨询";
            break;
        case 1:
            self.typelabel.text = @"常识";
            break;
        case 2:
            self.typelabel.text = @"问答";
            break;
        default:
            break;
    }
    
    NSString *status = [NSString stringWithFormat:@"%@",model.status];
    if([status isEqualToString:@"0"])
    {
        self.titleLabel.textColor = [UIColor colorFromHexCode:@"949494"];
        NSString *name = [NSString stringWithFormat:@"%@%@",@"[已作废]",model.title];
        NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:name];
        [attri addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 5)];
        [self.titleLabel setAttributedText:attri];
        self.telphonelabel.textColor = [UIColor colorFromHexCode:@"949494"];
        self.peoplelabel.textColor = [UIColor colorFromHexCode:@"949494"];
        self.typelabel.backgroundColor = [UIColor colorFromHexCode:@"949494"];
    }
}

-(NSString*)dateStringFromNow:(NSDate*)date{
    NSTimeInterval time = -[date timeIntervalSinceNow];
    if (time<0) {
        return @"";
    }else {
        if (time<3600*24) {
            if (time>=0.0 && time <60.0) {
                return @"刚刚";
            }else if (time>=60.0 && time <60.0*60.0) {
                return [NSString stringWithFormat:@"%d分钟前",(int)time/60];
            }else if (time>=3600.0 && time <3600.0*24) {
                return [NSString stringWithFormat:@"%d小时前",(int)time/3600];;
            }
        }else {
            
            NSCalendar* calendar = [NSCalendar currentCalendar];
            NSDateComponents* components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit|NSWeekCalendarUnit fromDate:date toDate:[NSDate date] options:0];
            if ([components year]>0) {
                int month = [components year]*12+[components month];
                return [NSString stringWithFormat:@"%d月前",month];
            }else if([components month]>0){
                int month = [components month];
                return [NSString stringWithFormat:@"%d月前",month];
            }else if([components week]>0){
                return [NSString stringWithFormat:@"%d周前",[components week]];
            }else if([components day]>0){
                return [NSString stringWithFormat:@"%d天前", [components day]];
            }
        }
    }
    return @"";
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
